package cc.lucien.servlet;

import cc.lucien.service.LoginService;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/img")
public class ImgServlet extends HttpServlet {

    LoginService loginService = new LoginService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        byte[] img = loginService.getImg(username);
        ServletOutputStream out = resp.getOutputStream();
        resp.setContentType("image/*");
        out.write(img);
        out.flush();
        out.close();
    }
}
